#include "../include/head.h"

int main()
{
    // 测试线程分配
    taskQueue_t queues[3];
    for(int i = 0;i<3;i++)
    {
        init_queue(&queues[i]);
    }
    //初始化三个共享资源结构体
    shareRes_t arges[3];


    //初始化pthread_Data
    pthread_data_t pthread_data;
    init_pthread_data(&pthread_data,3);

    //初始化clientinfo
    int clientInfo[1024];
    for(int i = 0;i<1024;i++)
    {
        clientInfo[i]=-1;
    }
    //初始化clientinfo锁
    pthread_mutex_t mutex_client_info = PTHREAD_MUTEX_INITIALIZER;

    //初始化标志位
    int exitFlag = 0;

    //创建线程池
    makeworker(arges,&pthread_data,clientInfo,&exitFlag,&mutex_client_info,queues);


    taskNode_t* node = in_node(66,99,C_OP_CD,"/",1,"xx",2);

    pthread_mutex_lock(&arges[0].mutex_taskqueue);
    tail_insert(&arges[0].taskqueue,node);
    pthread_mutex_unlock(&arges[0].mutex_taskqueue);


    taskNode_t* node2 = in_node(66,99,C_OP_CD,"/",1,"yy",2);

    pthread_mutex_lock(&arges[1].mutex_taskqueue);
    tail_insert(&arges[1].taskqueue,node2);
    pthread_mutex_unlock(&arges[1].mutex_taskqueue);

    taskNode_t* node3 = in_node(66,99,C_OP_CD,"/",1,"zz",2);

    pthread_mutex_lock(&arges[2].mutex_taskqueue);
    tail_insert(&arges[2].taskqueue,node3);
    
    pthread_mutex_unlock(&arges[2].mutex_taskqueue);

    for(int i =0;i<pthread_data.workernum;i++)
    {
        pthread_join(pthread_data.ptidarr[i],NULL);
    }

    // 测试路径栈
    // ServerVirtualPathStack *p = ServerVirtualPathStack_init();
    // char path_name1[] = "abc";
    // ServerVirtualPathStack_push(p, path_name1);

    // char path_name2[] = "ooo";
    // ServerVirtualPathStack_push(p, path_name2);

    // char path_name3[] = "kkk";
    // ServerVirtualPathStack_push(p, path_name3);

    // char str[1024] = {0};
    // ServerVirtualPathStack_print(p,str);
    // printf("%s\n", str);

    // ServerVirtualPathStack_pop(p);

    // char str2[1024] = {0};
    // ServerVirtualPathStack_print(p,str2);
    // printf("%s\n", str2);
    return 0;
}
